﻿
function InvokeSPExplorer() {
    ExecuteOrDelayUntilScriptLoaded(Initialize, 'sp.js');
}

function Initialize() {

    this.clientContext = new SP.ClientContext.get_current();
    this.oWeb = clientContext.get_web();
    this.oSite = clientContext.get_site();
    this.oList = oWeb.get_lists().getById(_spPageContextInfo.pageListId);
    this.clientContext.load(oList, 'Title');
	this.clientContext.load(oSite);
    this.clientContext.load(oWeb);
    this.clientContext.executeQueryAsync(Function.createDelegate(this, this.InitializeSuccess), Function.createDelegate(this, this.InitializeFail));

}


function InitializeSuccess(sender, args) {

    var ListName = oList.get_title();
    var SiteUrl = oSite.get_url();
    var WebRelativeUrl = oWeb.get_serverRelativeUrl();
    var SiteRelativeUrl = oSite.get_serverRelativeUrl();

    var FinalPath = "?SU=" + SiteUrl + "&WU=" + WebRelativeUrl.replace(SiteRelativeUrl, '') + "&LN=" + ListName + "&SRL=" + SiteRelativeUrl;
        
    OpenFormInDialog("Explorer", SiteUrl + "/SitePages/P3/P3.Tools.SPExplorer.aspx" + FinalPath);

}

function OpenFormInDialog(DialogTitle, DialogUrl) {
    var DialogForm =
    {
        title: DialogTitle,
        url: DialogUrl
    };

    SP.UI.ModalDialog.showModalDialog(DialogForm);
}

function InitializeFail(sender, args) {

    alert("Error Occured");

}